import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, DelDataButton, PrintQRCodeButton, SaveExcelButton } from '../Common/options'
import { LabReportTemplates } from '../Common/Conversion'

export const SampleParameter = async ({ OptionsEvent, oneData, Permission, actionRef }) => {
    const { LabReportData, LabReportEnum } = await LabReportTemplates()
    console.log(LabReportData)
    let dataList = {
        hideInSearch: true,
        pageSize: 10,
        params: { pageIndex: 1, sampleUuid: oneData.uuid },
        get: API_LIST([oneData.uuid])['getSampleItem'],
        added: 'posSampleItemAddSampleItem',
        initialValues: { sampleUuid: oneData.uuid },
        options: [
            Permission.findIndex(v => v.uuid === 'c57f2472-8450-411b-b79a-a17d64fa8dc7') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增配置参数" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'sampleUuid',
                title: '样品编号',
                valueType: 'hidden',
                hideInTable: true,
                hideInSearch: true,
                width: 150,
            },
            {
                dataIndex: 'displayNo',
                title: '样品编号',
                valueType: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 200,
            },
            {
                dataIndex: 'serialNo',
                title: '报告编号',
                valueType: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 200,
            },
            {
                dataIndex: 'labReportTemplateUuid',
                title: '报告名称',
                valueType: 'select',
                valueEnum: LabReportEnum,
                rules: true,
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'selectedTestTypeUuid',
                title: '报告参数',
                valueJudge: 'labReportTemplateUuid',
                JudgeValue: '',
                valueType: 'selectMultiple',
                fieldNames: { label: 'tableName', value: 'trueUuid' },
                multiple: true,
                valueEnum: LabReportData,
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'selectedTestTypeNames',
                title: '检测参数',
                type: 'hidden',
                ellipsis: true,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 300,
            },

            {
                dataIndex: 'tableName',
                title: '样品名称',
                valueType: 'input',
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'spec',
                title: '规格型号',
                valueType: 'input',
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'num',
                title: '数量',
                valueType: 'inputNumber',
                rules: true,
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'unit',
                title: '单位',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 100,
            },
            {
                dataIndex: 'sampleDisposal',
                title: '样品处置',
                valueType: 'input',
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'factoryName',
                title: '厂家名称',
                valueType: 'input',
                hideInSearch: true,
                width: 300,
            },
            {
                dataIndex: 'factorySerialNo',
                title: '出厂编号',
                valueType: 'input',
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'standardModifyNo',
                title: '报告唯一性标识',
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'factoryDate',
                title: '出厂日期',
                valueType: 'Date',
                hideInSearch: true,
                showTime: true,
                width: 200,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 350,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid } = record
                    return [
                        Permission.findIndex(v => v.uuid === '3d252f6f-a9dc-4877-99e7-269b87548256') !== -1 && (
                            <PrintQRCodeButton
                                OptionsEvent={OptionsEvent}
                                key="qrcode"
                                title="二维码"
                                url="SampleParameter"
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '5fa502ed-1a4a-4fb7-8884-a0543195060b') !== -1 && (
                            <SaveExcelButton
                                key="excel"
                                title="下载报告"
                                api={API_LIST()['getLabReport']}
                                data={{ SampleItemUuid: uuid }}
                            />
                        ),
                        // Permission.findIndex(v => v.uuid === '6c3362be-bdc7-4e6a-bbab-baa01cca911e') !== -1 && (
                        //     <OpenThrBtn
                        //         key="openThr"
                        //         upDataEvent={upDataEvent}
                        //         title="试验详情"
                        //         ThrKey="ThrModal"
                        //         value="SampleParameterDetails"
                        //         data={record}
                        //     />
                        // ),
                        Permission.findIndex(v => v.uuid === 'fd24d09d-a6f0-4f11-b7dd-ede0c2e7936a') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="SampleItem"
                                uuid={uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return dataList
}
